package com.hzw.saas.common.flow.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzw.saas.common.config.exception.DefaultSaasException;
import com.hzw.saas.common.flow.mapper.FlowNodeMapper;
import com.hzw.saas.common.flow.pojo.enums.FlowNodeStatus;
import com.hzw.saas.common.flow.pojo.model.FlowNode;
import com.hzw.saas.common.flow.service.IFlowNodeService;
import org.apache.ibatis.exceptions.TooManyResultsException;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sonam
 * @since 2021-08-04
 */
@Service
public class FlowNodeServiceImpl extends ServiceImpl<FlowNodeMapper, FlowNode> implements IFlowNodeService {

    @Override
    public FlowNode getStartNode(String flowId) {
        try {
            return this.lambdaQuery()
                .eq(FlowNode::getFlowId, flowId)
                .eq(FlowNode::getFlowNodeStatus, FlowNodeStatus.START_NODE).one();
        } catch (TooManyResultsException e) {
            throw DefaultSaasException.build("存在多个起始节点", e);
        }
    }
}
